package com.cennavi.minenavidemo.activity.map;

import android.graphics.Point;
import android.os.Bundle;

import androidx.appcompat.app.AppCompatActivity;

import com.cennavi.minenavidemo.R;
import com.cennavi.minenavidemo.presenter.MapPresenter;
import com.cennavi.minenavidemo.widget.MyMapView;
import com.minedata.minenavi.map.MineMap;
import com.minedata.minenavi.mapdal.LatLng;
import com.minedata.minenavi.mapdal.Tools;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

public class CircleActivity extends AppCompatActivity implements MapPresenter.OnMapViewListener {

    private Unbinder mUnbinder;
    @BindView(R.id.mapView)
    MyMapView mMapView;
    private MineMap mMineMap;
    private MapPresenter mMapPresenter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_circle);
        mUnbinder = ButterKnife.bind(this);
        init();
    }

    public void init() {
        mMapPresenter = MapPresenter.getInstance();
        mMapPresenter.init(CircleActivity.this, mMapView);
        mMapPresenter.setOnMapViewListener(this);
    }

    @Override
    protected void onPause() {
        if (mMapView != null) {
            mMapView.onPause();
        }

        super.onPause();
    }

    @Override
    protected void onResume() {
        if (mMapView != null) {
            mMapView.onResume();
        }

        super.onResume();
    }

    @Override
    protected void onDestroy() {
        mMapPresenter.deleteCircle();

        if (mMapView != null) {
            mMapView.onDestroy();
        }

        mUnbinder.unbind();
        super.onDestroy();
    }

    @Override
    public void onMapReady() {
        mMineMap = mMapPresenter.getMineMap();
        Point point = Tools.latLngToPoint(new LatLng(39.984059, 116.307771));
        mMineMap.setPointToCenter(point.x, point.y);
        mMineMap.setZoomLevel(11);
        mMapPresenter.addCircle();
    }

    @Override
    public void onswitchLocation(int imageLevel) {

    }
}
